<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"></c:set>

<html>
<head>
    <meta http-equiv="Access-Control-Allow-Origin" content="*" />

</head>

<body>
<h2>Hello World!</h2>
<button id="btnRequest">开始请求</button>
<button id="btnRequest2">开始请求jquery.jsonp</button>

<script src="${basePath }/static/plugins/jq/jquery-2.2.4.min.js"></script>
<script src="${basePath }/static/build/js/jquery.jsonp.js"></script>
<script>

    $('#btnRequest').click(function () {
        $.ajax({
            url: 'https://www.diecolor.com/dcms/test/jsonp',
            data:{param:13},
            dataType:"jsonp",
            jsonp:"callback",
            jsonpCallback:"success_jsonp",
            timeout:3000,
            dataFilter:function(json){
                console.log("jsonp.filter:"+json);
                return json;
            },
            success:function(json,textStatus){
                console.log("jsonp.success:"+json.name);
            },
            error:function(XMLHttpRequest,textStatus,errorThrown){
                console.log("jsonp.error:"+textStatus);
            }
        })
    })

    $('#btnRequest2').click(function () {
        $.jsonp({
            url:'https://www.diecolor.com/dcms/test/jsonp',
            data:{param:13},
            callbackParameter:"callback",
            timeout:3000,
            dataFilter:function(json){
                console.log("jsonp.filter:"+json.name);
                json.name = "测试123435";
                return json;
            },
            success:function(json,textStatus,xOptions){
                console.log("jsonp.success:"+json.name);
            },
            error:function(xOptions,textStatus){
                console.log("jsonp.error:"+textStatus+", rel="+xOptions.data.rel);
            }
        });
    })


</script>
</body>
</html>
